/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-11-03
 * Time: 20:49
 */
class Solution4 {
    public int searchInsert(int[] nums, int target) {
        if(nums.length == 0){
            return 0;
        }
        int targetLeft = 0  , n = nums.length;
        int left = 0 , right = nums.length-1;
        //这道题只用找一个左界限就够了

        //左界限
        left = 0 ; right = n-1;
        while(left < right){
            int mid = left + (right - left)/2;//左端点
            if(nums[mid] >= target){
                right = mid;
            }else{
                left = mid + 1;
            }
        }
        targetLeft = left;


        int result = 0;


        if(target > nums[targetLeft]){
            result = targetLeft + 1;
        }else{
            result = targetLeft ;
        }





        return result;
    }
}
public class Test4 {
    public static void main(String[] args) {
        Solution4 s = new Solution4();
        int[] nums = {1,3,5,6};
        s.searchInsert(nums,2);
    }
}
